/*
 *  Copyright 2020-2025 the original author or authors.
 *  You cannot use this file unless authorized by the author.
 */

package org.ipig.computing.cluster.yarn;

import lombok.extern.slf4j.Slf4j;
import org.ipig.messaging.ConsumerService;
import org.ipig.messaging.kafka.consumer.GenericKafkaConsumer;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.CountDownLatch;

/**
 * SparkOnYarnLauncher
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @since 1.0
 */
@Slf4j
public class SparkOnYarnLauncher {
    /**
     * main
     *
     * @param args
     */
    public static void main(String[] args) {
        final CountDownLatch latch = new CountDownLatch(1);
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/config/beans.xml");
        //catch control-c
        Runtime.getRuntime().addShutdownHook(new Thread("SparkOnYarnLauncher-shutdown-hook") {
            @Override
            public void run() {
                context.close();
                latch.countDown();
            }
        });

        try {
            context.start();
            ConsumerService consumer = context.getBean("genericKafkaConsumer", GenericKafkaConsumer.class);
            consumer.execute();
            latch.await();
        } catch (Throwable e) {
            System.exit(1);
        }
        System.exit(0);
    }
}
